<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="sourceZone">
      <div>原始区域:</div>

      <div id="sourceButtons">
        <div>
          <button class="btn1" onclick="console.log('按钮1被点击了')">
            按钮1(代码)
          </button>
        </div>
        <div>
          <button class="btn2">按钮2(函数)</button>
        </div>
      </div>
    </div>

    <div id="copyZone">
      <div>复制区域:</div>
    </div>

    <script>

      document.querySelector(".btn2").onclick = onClick2;

      copyZone.append(sourceButtons.cloneNode(true));

      function onClick2() {
        console.log("按钮2被点击了");
      }

      (function () {
        function onClick4() {
          console.log("按钮4被点击了");
        }
      })();
    </script>
  </body>
</html>
